//
//  ViewController.m
//  自定义控件
//
//  Created by apple on 15/9/11.
//  Copyright (c) 2015年 戴维营. All rights reserved.
//

#import "ViewController.h"
#import "CustomView.h"

@interface ViewController ()<CustomDelegate>
{
    CustomView *_customView;
    
}


@end

@implementation ViewController

- (void)touchDown:(CustomView *)sender index:(int)index
{
    NSLog(@"%s",__PRETTY_FUNCTION__);
}

- (UIColor *)changeColor
{
    return [UIColor blueColor];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _customView = [[CustomView alloc] initWithFrame:CGRectMake(20, 100, 200, 60)];
    
    
    _customView.backgroundColor = [UIColor orangeColor];
    
    _customView.aLabel.backgroundColor = [UIColor redColor];
    
    _customView.bLabel.backgroundColor = [UIColor blueColor];
    
    
    //必须实现的代理
    _customView.delegate = self;
    
    _customView.aLabel.text = @"天王盖地虎！";
    
    _customView.bLabel.text = @"宝塔镇河妖！";
    
    
    _customView.touchDown = ^(CustomView *sender,int index)
    {
        NSLog(@"%@,%d",sender,index);
    };
    
    _customView.changeColor = ^
    {
        return [UIColor purpleColor];
    };
    
    [self.view addSubview:_customView];
    
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    
    CGPoint point = [touch locationInView:self.view];
    
  
    CGRect rect = _customView.frame;
    
    rect.origin = point;
    
    rect.size = CGSizeMake(point.x,point.y);
    
    _customView.frame = rect;
    
    
    
//    CGRect rect = CGRectMake(point.x, point.y, 300, 400);
//    
//    _customView.frame = rect;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
